#include <algorithm>
#include <cstdio>

const int N = 25, mod = 1e9 + 7;
int n, m, x, ans, a[N + 1], fact[N + 1];
char opt;

void dfsand(int i, int sta, int tot) {
  if (i > n) {
    if (sta == x && tot) ans += fact[tot];
    return;
  }
  dfsand(i + 1, sta & a[i], tot + 1);
  dfsand(i + 1, sta, tot);
}

void dfsor(int i, int sta, int tot) {
  if (i > n) {
    if (sta == x && tot) ans += fact[tot];
    return;
  }
  dfsor(i + 1, sta | a[i], tot + 1);
  dfsor(i + 1, sta, tot);
}

void dfsxor(int i, int sta, int tot) {
  if (i > n) {
    if (sta == x && tot) ans += fact[tot];
    return;
  }
  dfsxor(i + 1, sta ^ a[i], tot + 1);
  dfsxor(i + 1, sta, tot);
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
  freopen("xx.in", "r", stdin);
  freopen("xx.out", "w", stdout);
#endif
#endif

  scanf("%c%d%d", &opt, &n, &m);
  for (int i = 1; i <= n; ++i) {
    for (int j = 0, tmp; j < m; ++j) {
      scanf("%d", &tmp);
      a[i] |= tmp << j;
    }
  }
  for (int j = 0, tmp; j < m; ++j) {
    scanf("%d", &tmp);
    x |= tmp << j;
  }
  fact[0] = 1;
  for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i % mod;
  switch (opt) {
    case '&':
      dfsand(1, (1 << m) - 1, false);
      break;
    case '|':
      dfsor(1, 0, false);
      break;
    case '^':
      dfsxor(1, 0, false);
      break;
  }
  printf("%d", ans);
  return 0;
}